package com.scpii.universal.test;

import java.util.List;

import com.scpii.universal.client.Client;
import com.scpii.universal.pb.PbUniversal.PBCMD;
import com.scpii.universal.pb.PbUniversal.PbPageContentPageCS;
import com.scpii.universal.pb.PbUniversal.PbPageContentPageSC;
import com.scpii.universal.pb.PbUniversal.PbViewCatelogPageCS;
import com.scpii.universal.pb.PbUniversal.PbViewCatelogPageSC;
import com.scpii.universal.pb.PbUniversal.PbViewContentPageCS;
import com.scpii.universal.pb.PbUniversal.PbViewContentPageSC;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContent;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContentList;
import com.scpii.universal.pb.PbUniversalBasic.PbContentAttributeValue;
import com.scpii.universal.pb.PbUniversalBasic.PbContentAttributeValueList;
import com.scpii.universal.pb.PbUniversalBasic.PbPageViewCatelog;
import com.scpii.universal.pb.PbUniversalBasic.PbPageViewCatelogList;

public class PageEntrance {
	public static void PbViewCatelogPageSC() throws Exception {
		PbViewCatelogPageCS.Builder pbViewCatePageCSB = PbViewCatelogPageCS.newBuilder();
		pbViewCatePageCSB.setIntPageNum(1);
		pbViewCatePageCSB.setIntViewId(2121);
		
		byte[] bytes = pbViewCatePageCSB.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PbViewCatelogPageCMD.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PbViewCatelogPageSC pbViewCatePageSC = PbViewCatelogPageSC.parseFrom(returnBytes);
			System.out.println("执行结果："+pbViewCatePageSC.getExeResult().toString());
			
			PbPageViewCatelogList pbPageViewCateList = pbViewCatePageSC.getPbPageViewCatelogList();
			List<PbPageViewCatelog> pbPageVCList = pbPageViewCateList.getPbPageViewCatelogList();
			if (pbPageVCList!=null && pbPageVCList.size()>0) {
				for (PbPageViewCatelog pbpvc : pbPageVCList) {
					System.out.println("分类ID："+pbpvc.getIntCateId());
					System.out.println("下一页页面类型："+pbpvc.getIntNextPageType());
					System.out.println("下一页页面ID"+pbpvc.getIntResourceId());
					System.out.println("视图分类ID："+pbpvc.getIntViewCateId());
					System.out.println("视图ID:"+pbpvc.getIntViewId());
					
					System.out.println("分类简介："+pbpvc.getVarCateDescrip());
					System.out.println("分类缩略图："+pbpvc.getVarCateImgUrl());
					System.out.println("分类名称："+pbpvc.getVarCateName());
					
					PbContentAttributeValueList pbContAttrValueList = pbpvc.getPbContentAttributeValueList();
					List<PbContentAttributeValue> pbCAVList = pbContAttrValueList.getPbContentAttributeValueListList();
					if (pbCAVList!=null && pbCAVList.size()>0) {
						for (PbContentAttributeValue pbcontAV : pbCAVList) {
							System.out.println("属性ID："+pbcontAV.getIntAttriId());
							System.out.println("属性显示顺序："+pbcontAV.getIntAttriOrder());
							System.out.println("属性值ID："+pbcontAV.getIntAttriValueId());
							System.out.println("内容ID："+pbcontAV.getIntContentId());
							
							System.out.println("属性名称："+pbcontAV.getVarAttriName());
							System.out.println("属性值"+pbcontAV.getVarAttriValue());
						}
					}
				}
			}
		}
	}
	
	public static void PbViewContentPageCMD()throws Exception{
		PbViewContentPageCS.Builder pbViewContPageCSB = PbViewContentPageCS.newBuilder();
		pbViewContPageCSB.setIntPageNum(2);
		pbViewContPageCSB.setIntViewId(2121);
		
		byte[] bytes= pbViewContPageCSB.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PbViewContentPageCMD.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PbViewContentPageSC pbViewContentPageSC = PbViewContentPageSC.parseFrom(returnBytes);
			System.out.println("执行结果为："+pbViewContentPageSC.getExeResult().toString());
			PbAppPageContentList pbAppPageContList = pbViewContentPageSC.getPbAppPageContentList();
			List<PbAppPageContent> pbAPCList = pbAppPageContList.getPbAppPageContentList();
			if (pbAPCList!=null && pbAPCList.size()>0) {
				for (PbAppPageContent pbAPC : pbAPCList) {
					System.out.println("///////////////////////////////////");
					System.out.println("应用ID："+pbAPC.getIntAppId());
					System.out.println("分类ID："+pbAPC.getIntCateId());
					System.out.println("内容ID："+pbAPC.getIntContentId());
					System.out.println("详细页面类型："+pbAPC.getIntDetailPageType());
					System.out.println("企业ID："+pbAPC.getIntEnterpId());
					System.out.println("访问次数："+pbAPC.getIntViewCount());
					System.out.println("内容简介："+pbAPC.getVarContentDescrip());
					System.out.println("内容缩略图："+pbAPC.getVarContentImgUrl());
					System.out.println("内容名称："+pbAPC.getVarContentName());
					System.out.println("详情页面访问地址："+pbAPC.getVarDetailPageUrl());
					
					PbContentAttributeValueList pbContAttrValueList = pbAPC.getPbContentAttributeValueList();
					List<PbContentAttributeValue> pbCAVList = pbContAttrValueList.getPbContentAttributeValueListList();
					if (pbCAVList!=null && pbCAVList.size()>0) {
						for (PbContentAttributeValue pbcontAV : pbCAVList) {
							System.out.println("=================================");
							System.out.println("属性ID："+pbcontAV.getIntAttriId());
							System.out.println("属性显示顺序："+pbcontAV.getIntAttriOrder());
							System.out.println("属性值ID："+pbcontAV.getIntAttriValueId());
							System.out.println("内容ID："+pbcontAV.getIntContentId());
							
							System.out.println("属性名称："+pbcontAV.getVarAttriName());
							System.out.println("属性值:"+pbcontAV.getVarAttriValue());
						}
					}
				}
			}
		}
	}
	
	public static void PbPageContentPageCMD(int pageNum)throws Exception{
		PbPageContentPageCS.Builder pbPageContPageB = PbPageContentPageCS.newBuilder();
		pbPageContPageB.setIntAppId(1060);
		pbPageContPageB.setIntCatelogId(1218);
		pbPageContPageB.setIntPageNum(pageNum);
		pbPageContPageB.setIntViewId(1224);
		
		byte[] bytes = pbPageContPageB.build().toByteArray();
		byte[] returnBytes = Client.testPOSTMethod(PBCMD.PbPageContentPageCMD.getNumber(), bytes);
		if (returnBytes!=null && returnBytes.length>0) {
			PbPageContentPageSC pbPageContentPageSC = PbPageContentPageSC.parseFrom(returnBytes);
			System.out.println("执行结果："+pbPageContentPageSC.getExeResult().toString());
			PbAppPageContentList pbAppPageContentList = pbPageContentPageSC.getPbAppPageContentList();
			List<PbAppPageContent> pbAppPageConList = pbAppPageContentList.getPbAppPageContentList();
			System.out.println("=================================");
			if (pbAppPageConList!=null && pbAppPageConList.size()>0) {
				for (PbAppPageContent pbCont : pbAppPageConList) {
					System.out.println("------------------------------------");
					System.out.println(pbCont.getDatAddDate());
					System.out.println(pbCont.getIntAppId());
					System.out.println(pbCont.getIntCateId());
					System.out.println(pbCont.getIntDetailPageType());
					System.out.println(pbCont.getIntViewCount());
					
					System.out.println(pbCont.getVarContentDescrip());
					System.out.println(pbCont.getVarContentImgUrl());
					System.out.println(pbCont.getVarContentName());
					System.out.println(pbCont.getVarDetailPageUrl());
				}
			}
		}
	}

	public static void main(String[] args) {
		try {
//			PbViewCatelogPageSC();
			PbViewContentPageCMD();
//			for (int i = 0; i < 20; i++) {
//				System.out.println("++++++++++++++第（"+i+"页）++++++++++++++");
//				PbPageContentPageCMD(i);
//			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
